<template>
  <view class="flex-col">

    <view :class="boole?'bottom115':''">
      <!--基础信息-->
      <basic-info v-model="detailForm"/>

      <!--年检信息-->
      <inspection-info v-model="detailForm" :boole="boole" ref="refInspectionInfo"/>

      <!--审批流程-->
      <exam-flow v-if="flowId" :instanceId="flowId"/>
    </view>

    <view class="button-container" v-if="boole">
      <button class="btn-item" @click="submit">提 交</button>
    </view>

  </view>
</template>

<script>
import {getInspectionDetails, addInspection, feedbackList} from "@/api/inspection";
import basicInfo from './components/basicInfo.vue'
import inspectionInfo from './components/inspectionInfo.vue'

export default {
  name: 'add',
  components: {basicInfo, inspectionInfo},
  computed: {},
  watch: {},
  data() {
    return {
      boole: false,
      flowId: null,
      detailForm: {
        //年检信息
        workId: "",
        inspectionTime: "",
        onlineOffline: "",
        inspectionNextTime: "",
        expireOnlineOffline: "",
        inspectionPrice: "",
        inspectionAgentPrice: "",
        comprehensivePrice: "",
        twoDimensionPrice: "",
        otherPrice: "",
        inspectionAllPrice: "",
        inspectionIdenUrl: "",
        inspectionInvoiceUrl: "",
        remark: "",
        region:'',
        workCreateTime:'',


        //车辆信息
        carNo: "",
        vinNo: "",
        brandName: "",
        seriesName: "",
        modelName: "",
        propertyRightName: "",
        ascription: "",
        orderCode: "",
        customerName: "",
        contractType: "",
        carNature: "",
        businessType: "",
        registerTime: "",
        seatNum:"",
        fuelType:'',
        lastOnlineOffline: "",
        inspectionLastTime: "",
        attachmentUrl: "",
        carId: '',
        isOurCompanyInspection:'',
        isFirstInspect:'',
        inStorageInspect:'',
      },
      opObj: {}
    };
  },
  created() {
  },
  onLoad(op) {
    let title = "";
    this.flowId = op?.flowId;
    this.detailForm.carId = op?.carId
    this.opObj = op
    this.feedbackList(op?.id)
    if (op?.type === "edit") {
      title = "新增年检工单";
      this.boole = true;
    }
    if (op?.type === "view") {
      this.inspectDetails(op?.businessDataId)
      title = "年检工单详情";
      this.boole = false;
    }
    this.detailForm.carId = op?.carId;
    uni.setNavigationBarTitle({
      title,
    });
  },
  mounted() {
  },
  methods: {
    // 获取基础信息
    async feedbackList(id) {
      let idList = []
      idList.push(id)
      try {
        const res = await feedbackList(idList)
        for (let key in this.detailForm) {
          this.$set(this.detailForm, key, res[0][key])
        }
      } catch (e) {
        console.error(e)
      }
    },

    // 详情回显
    inspectDetails(id) {
      getInspectionDetails(id).then(res => {
        if (res.code === 200) {
          this.isForm = true
          for (let key in res.data) {
            this.$set(this.detailForm, key, res.data[key])
          }
        }
      })
    },

    async submit() {
      try {
        await this.$refs.refInspectionInfo.handleEffect()
        uni.showLoading();
        this.detailForm.workOrderStatus = "2"
        this.detailForm.workId = this.opObj?.id
        this.detailForm.carId = this.opObj?.carId
        let res = await addInspection([this.detailForm])
        if (res.code === 200) {
          uni.$emit("refBackList", true);
          this.$modal.msgSuccess("提交成功");
          setTimeout(() => {
            this.$tab.navigateBack();
          }, 1000);
        }
      } catch (error) {
        if (typeof error === 'string') {
          this.$nextTick(() => {
            uni.pageScrollTo({
              selector: error,
            });
          });
        } else {
          console.error(error)
        }
      } finally {
        setTimeout(()=>{uni.hideLoading()},1000)
      }
    },
  },
};
</script>

<style scoped lang=""></style>


